import React, {Component} from 'react';

import Api from './../Api'

class Welcome extends Component {

    constructor(props) {
        super(props)
        this.state = {user: {}};
    }

    componentDidMount() {
        Api.getUserInfo((data, err)=> {
            if (data) {
                this.setState({
                    user: data.data
                })
            } else {
                this.setState({
                    user: {
                        name: 'wtf?'
                    }
                })
            }
        });
    }

    render() {
        const {user} = this.state;
        return <div>
            {user.name ? `Welcome ${user.id}` : `Loading...`}
        </div>
    }
}

export default Welcome;
